/**
 * @file    Hoszab.c
 * @author  Csörnyei Ádám
 * @brief   Diplomaterv 1 hőszabályozó beágyazott szoftvere
 * @date    February 19, 2011, 10:37 PM
 * @version v0.1
 *
 * @mainpage My Personal Index Page
 * @section intro_sec Introduction
 *
 * @section install_sec Installation
 * @subsection step1 Step 1: Opening the box
 */


/**
 * @def DEBUG
 * @brief Definiálja a DEBUG makrót a teszt funkciók aktiválásához,
 * különben a RELEASE makró használatával élesen tesztelhet.
 * 
 * @def RELEASE
 * @brief A DEBUG makró kommentezésével a RELEASE makró aktiválódik,
 * amely a szoftver véglegesített komponenseit szelektálja.
 */

#define DEBUG
#ifndef DEBUG
    #define RELEASE
#endif

//#define __AVR_ATmega8__
//#define _AVR_IO_H_

/*
#include "./avr/portpins.h"
#include "./avr/sfr_defs.h"
#include "./avr/common.h"
#include "./avr/version.h"
#include "./avr/fuse.h"
#include "./avr/lock.h"
#include "./avr/iom8.h"
*/

#include "io.h"
#include "interrupt.h"

/**
 * @def st(x)
 * @brief Makró csomagoló.
 */
#define st(x) do{x} while(__LINE__ == -1)


//AD592

/**
 * @def SET_BITS(MASK,REG)
 * @brief Beállítja [1] a @a REG regiszter azon helyiértékű bitjeit, ahol
 * a @a MASK regiszterben [1] található.
 *
 * @def CLR_BITS(MASK,REG)
 * @brief Törli [0] a @a REG regiszter azon helyiértékű bitjeit, ahol
 * a @a MASK regiszterben [1] található.
 *
 * @def TOG_BITS(MASK,REG)
 * @brief Megváltoztatja a @a REG regiszter azon helyiértékű bitjeit, ahol
 * a @a MASK regiszterben [1] található.
 */

#define SET_BITS(MASK,REG) st(REG |= MASK;)
#define CLR_BITS(MASK,REG) st(REG &= ~(MASK);)
#define TOG_BITS(MASK,REG) st(REG ^= MASK;)

/**
 * @addtogroup ICP
 * Az ICP-hez kapcsolódó definíciók
 *
 * @{
 */

/**
 * @def ICP_ICNC_ON
 * @brief Input Capture Noise Canceller bekapcsolás szint flag
 *
 * @def ICP_ICNC_OFF
 * @brief Input Capture Noise Canceller kikapcsolás szint flag
 *
 * @def ICP_RISING
 * @brief Input Capture Unit felfutó él érzékenység szint flag
 *
 * @def ICP_FALLING
 * @brief Input Capture Unit lefutó él érzékenység szint flag
 *
 * @def ICP_IT_SET
 * @brief Input Capture megszakítás engedélyezés szint flag
 *
 * @def ICP_IT_CLR
 * @brief Input Capture megszakítás tiltás szint flag
 */

#define ICP_ICNC_ON     1
#define ICP_ICNC_OFF    0
#define ICP_RISING      1
#define ICP_FALLING     0
#define ICP_IT_SET      1
#define ICP_IT_CLR      0

/**
 * @def ICP_PRESCALE(x)
 * @brief A Timer 1 (Input Capture Unit) órajelének előosztása.
 *
 * Beállítható értékek: [0,1,8,64,256,1024].
 * A rendszer órajel 1MHz.
 */
#define ICP_PRESCALE(x) st(\
			switch(x){\
				case 0:\
					SET_BITS(0x00,TCCR1B);\
					CLR_BITS((1<<CS10)|(1<<CS11)|((1<<CS12),TCCR1B);\
					break;\
				case 1:	\
					SET_BITS((1<<CS10),TCCR1B);\
					CLR_BITS((1<<CS11)|(1<<CS12),TCCR1B);\
					break;\
				case 8:	\
					SET_BITS((1<<CS11),TCCR1B);\
					CLR_BITS((1<<CS10)|(1<<CS12),TCCR1B);\
					break;\
				case 64:\
					SET_BITS((1<<CS10)|((1<<CS11),TCCR1B);\
					CLR_BITS((1<<CS12),TCCR1B);\
					break;\
				case 256:\
					SET_BITS((1<<CS12),TCCR1B);\
					CLR_BITS((1<<CS10)|(1<<CS11),TCCR1B);\
					break;\
				case 1024:\
					SET_BITS((1<<CS10)|(1<<CS12),TCCR1B);\
					CLR_BITS((1<<CS11),TCCR1B);\
					break;\
				default:\
					break;\
			};\
		);

/**
 * @def ICP_STOP()
 * @brief Leállítja Timer 1-et (Input Capture Unit).
 *
 * @def ICP_SET_EDGE(x)
 * @brief ICP élérzékenység beállítása.
 *
 *  Ha @a x @ref ICP_FALLING :lefutó él, @ref ICP_RISING : felfutó él.
 *
 * @def ICP_GET_EDGE()
 * @brief ICP élérzékenység lekérdezése.
 *
 * Ha felfutó él: @ref ICP_RISING, ha lefutó él: @ref ICP_FALLING.
 *
 * @def ICP_SET_ICNC(x)
 * @brief Input Capture Noise Canceller ki- és bekapcsolás.
 *
 * Ha @a x @ref ICP_ICNC_ON :bekapcsolás, @ref ICP_ICNC_OFF :kikapcsolás.
 * Működése 4 órajel késleltetést visz az érzékelésbe.
 *
 * @def ICP_SET_IT(x)
 * @brief Input Capture Unit megszakításkérés ki- és bekapcsolás.
 *
 * Ha @a x @ref ICP_IT_SET :bekapcsolás, @ref ICP_IT_CLR :kikapcsolás.
 */
#define ICP_STOP() st(ICP_PRESCALE(0);)
#define ICP_SET_EDGE(x) st(x?SET_BITS((1<<ICES1),TCCR1B):CLR_BITS((1<<ICES1),TCCR1B);)
#define ICP_GET_EDGE() st(((1<<ICES1)&TCCR1B)?ICP_RISING:ICP_FALLING;)
#define ICP_SET_ICNC(x) st(x?SET_BITS((1<<ICNC1),TCCR1B):CLR_BITS((1<<ICNC1),TCCR1B);)
#define ICP_SET_IT(x) st(x?SET_BITS((1<<TICIE1),TIMSK):CLR_BITS((1<<TICIE1),TIMSK);)

/** @} */


//1] The sum of all IOL, for all ports, should not exceed 300 mA. 
//2] The sum of all IOL, for ports C0 - C5 should not exceed 100 mA. 
//3] The sum of all IOL, for ports B0 - B7, C6, D0 - D7 and XTAL2, should not exceed 200 mA.

//Munkaponti áram 11.8mA a 7 szegmenses kijelzőn, 8.4mA az optotriaknak
//bőven teljesítik a feltételeket
//DEAD pixel a bal alsó sarokban

/**
 * @def PIN_IN
 * @brief Pin input szint flag.
 *
 * @def PIN_OUT
 * @brief Pin output sint flag.
 */

#define PIN_IN      0 //pin direction: in
#define PIN_OUT     1 //pin direction: out

#define ICP_ICNC     1 //input capture noise canceller 1:on
#define ICP_EDGE     0 //input capture trigger edge 0:falling
#define T1_EDGE     0 //Timer1 ext.trigger edge 0:falling   

#define TIMER1_FALLING_EDGE 0
#define TIMER1_RISIG_EDGE   1

// #define OSC_FREQUENCY 32768
// 
// volatile uint8_t SegSel = 0;
// volatile char segmentChanged = 0;
// volatile uint16_t ICP_current = 0;
// volatile uint16_t ICP_prev = 0;
// volatile char measure_finished = 0;
// volatile char measure_enable = 1;
// volatile char measure_calculated = 0;
// volatile uint16_t RPM = 0;

/**
 * @var uint8_t display[]
 * @brief Egy tömb, amely elemei a kijelzőszegmensekre kiadandó
 * kész logikai kódot tartalmazzák.
 *
 * Mivel a kijelző szegmenseinek vezérlő pinjei több
 * portra lettek kiosztva, az elemek értékei logikaiak,
 * de a kiadandó kódot tartalmazzák, amelyet maszkolva
 * és szétválasztva a portokra adandó kód kinyerhető.
 */

uint8_t display[] = {0x0FF,0x0FF,0x0FF};

//     a
//   -----
//  |     |
// f|    b|
//  |  g  |
//   -----
//  |     |  
// e|    c| 
//  |  d  |
//   -----

// PC1 2 3 4 5 
//   A B C D E

// PD0 1 2 3 4 5
//   F G p 1 2 3

// seg_number
// 7  6  5  4  3  2  1  0
// DP G  F  E  D  C  B  A

/* Number Table 0 1 2 3 4 5 6 7 8 9 - None */
//LOW-ACTIVE
// const uint8_t seg_numbers[]={
//     0x01, 0x4F, 0x12,
//     0x06, 0x4C, 0x24,
//     0x20, 0x0F, 0x00, 0x7B};

#define LEDLOMASK 0x3E //apply after shifting the byte 1 left
#define LEDHIMASK 0xE0 //apply directly
#define LEDHIMASK_L 0x07 //apply directly

const uint8_t seg_numbers[]={
     0xC0, 0xF9, 0xA4,
     0xB0, 0x9B, 0x94,
     0x84, 0xF8, 0x00, 0x3F, 0xFF};
    
void DisplayWrite(uint8_t num){
	uint8_t temp;
	uint8_t i;
	
	for(i=0;i<3;i++){
		temp = num%10;
		display[i] = temp;
		num -= temp;
		num /= 10;
	}
}   

void DisplayErase(){
	display[0] = seg_numbers[11];
	display[1] = seg_numbers[11];
	display[2] = seg_numbers[11];
}

void DisplayLine(){
	display[0] = seg_numbers[10];
	display[1] = seg_numbers[10];
	display[2] = seg_numbers[10];
}

uint8_t DisplayDigit = 0;

void DisplayRefresh(){
	uint8_t mask;
	
	DisplayDigit++;
	DisplayDigit = DisplayDigit % 3;
	mask = display[DisplayDigit] << 1;
	mask &= LEDLOMASK;
	SET_BITS(mask,PORTC);	
	CLR_BITS((~mask) & LEDLOMASK,PORTC);

	mask = display[DisplayDigit] & LEDHIMASK;
	mask = mask >> 5;
	SET_BITS(mask,PORTD);
	mask = (~mask) & LEDHIMASK_L;
	CLR_BITS(mask,PORTD);
	
	CLR_BITS((PD3+DisplayDigit) << 1,PORTD);
}

void PortInit(){
    /*
    FUSES:
        DEFAULT:
        CKSEL = 0001, SUT = 10, CKOPT [unprogrammed]
        //SUT = 00 BOD enabled//
        1MHz internal RC oscillator
        slowly rising power [longest start-up time 65 ms]
    */
    
    /* unused pins are inputs with internal pullup*/

    //disable interrupts
    cli();
    
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //setting ports first, while they are tri-state inputs
    //because control signals are low-active, setting them
    //active would cause all display segments to light up
    //and the controller couldn't bear such a high current
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    

    //All inputs, PB0 without pullup, others with it
    PORTB = (0<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|
            (1<<PB4)|(1<<PB5)|(1<<PB6)|(1<<PB7);

    //PC0, PC6 in, no pullup, others out, Lo-active
    PORTC = (0<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|
            (1<<PC4)|(1<<PC5)|(0<<PC6);

    //All outputs except PD7 (pullup), LO-active except PD6
    PORTD = (1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3)|
            (1<<PD4)|(1<<PD5)|(0<<PD6)|(1<<PD7);

        
    //All inputs
    DDRB = 	(xIN<<DDB0)|(xIN<<DDB1)|(xIN<<DDB2)|(xIN<<DDB3)|
            (xIN<<DDB4)|(xIN<<DDB5)|(xIN<<DDB6)|(xIN<<DDB7);    
            
    //PC0, PC6 in
    DDRC =	(xIN<<DDC0)|(xOUT<<DDC1)|(xOUT<<DDC2)|(xOUT<<DDC3)|
            (xOUT<<DDC4)|(xOUT<<DDC5)|(xIN<<DDC6);    

    //All outputs except PD7
    DDRD =	(xOUT<<DDD0)|(xOUT<<DDD1)|(xOUT<<DDD2)|(xOUT<<DDD3)|
            (xOUT<<DDD4)|(xOUT<<DDD5)|(xOUT<<DDD6)|(xIN<<DDD7);
}

void AdcInit(){
    //configure the ADC for ADC0 polling

    //disable interrupts
    cli();

    //REF is AVCC, Left adjustment, Channel 0    
    ADMUX = (1<<REFS1)|(0<<REFS0)|(1<<ADLAR)|(0<<MUX3)|
            (0<<MUX2)|(0<<MUX1)|(0<<MUX0);    
            
    //ADC enable, start first conversion (calibration)
    //single conversion mode, clear IT flag
    //prescaler set to 8 (125kHz)
    ADCSRA = (1<<ADEN)|(1<<ADSC)|(0<<ADFR)|(1<<ADIF)|
             (0<<ADIE)|(0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
}

uint8_t AdcStart(){
    //AdcInit a priori
    //supposes ADIF is cleared
    
    if(ADCSRA & (1<<ADSC)){//conversion in progress
        return 0;
    }else{
        ADCSRA |= (1<<ADSC);//start conversion
    }
}

void ICPInit(){
	// no input filter, rising edge, no prescaling
	//ICP_SET_EDGE(ICP_RISING);
		SET_BITS((1<<ICES1),TCCR1B);
	//ICP_SET_ICNC(ICP_ICNC_OFF);
		SET_BITS((1<<ICES1),TCCR1B);
	//ICP_PRESCALE(1);
		SET_BITS((1<<CS10),TCCR1B);
		CLR_BITS((1<<CS11)|(1<<CS12),TCCR1B);
}

volatile uint8_t MODE;
volatile uint8_t ICP_FLAG = 0;
volatile uint16_t ICP_prev = 0;
volatile uint16_t ICP_cur = 0;

#define CALIBRATION 0

// ISR(TIMER1_ICP_vect){
// 	switch(MODE){
// 		case CALIBRATION:
// 		//toggle edge selection, if a measrement is completed, set flag
// 		ICP_prev = ICP_cur;
// 		ICP_cur = ICR1;
// 		if((1<<ICES1) & TCCR1B){//rising edge occured
// 		
// 		}
// 	}
// }


int main(){

    uint16_t temp;
    //uint8_t tempseg;

    cli();

    //PortInit();
    //AdcInit();
    
    while(1){
    	#ifdef DEBUG
   	 		
   	 	//CLR_BITS(PD3<<1,PORTD);
   	 	//CLR_BITS(PD1<<1,PORTD);
   	 	DDRB = 0xff;
   	 	PORTD = 0;
		
		#else
		
        if(ADCSRA & (1<<ADIF)){//conversion complete
            temp = ADCH;
            ADCSRA &= ~(1<<ADIF);
            AdcStart();
        }       
       #endif

    }
    return 0;
}
       
/*
#ifdef DEBUG
    display[0]=seg_numbers[1];
    display[1]=seg_numbers[2];
    display[2]=seg_numbers[3];
#endif


    sei();

    while(1){

        if(segmentChanged){
            PORTD &= (0<<SegSel);
            tempseg = display[SegSel]<<3;            
            PORTD = 0x03&&tempseg;
            tempseg = display[SegSel]>>2;
            PORTB = 0x1F&&tempseg;
            segmentChanged = 0;
        }

#ifndef DEBUG

        if(measure_calculated){
            measure_calculated = 0;
            
            if(RPM < 100){
            //if measurement could not be displayed, refreshing is disabled
                TIMSK = (1<<TOIE1)|(0<<OCIE1A)|(0<<OCIE1B)|(1<<ICIE1)|
                        (0<<OCIE0B)|(0<<TOIE0)|(0<<OCIE0A)|(0<<4);
                PORTB |= 0x1F;//deactivate display
                PORTD |= 0x1F;
                segmentChanged = 0;
            }
            else
            {
                TIMSK = (1<<TOIE1)|(0<<OCIE1A)|(0<<OCIE1B)|(1<<ICIE1)|
                        (0<<OCIE0B)|(1<<TOIE0)|(0<<OCIE0A)|(0<<4);
                        
                temp = RPM/100;
                //lustaságból nem szervezek ciklust
                switch(temp%10)//rightmost segment
                {
                    case 0:
                        display[0]=seg_numbers[0];
                        break;
                    case 1:
                        display[0]=seg_numbers[1];
                        break;
                    case 2:
                        display[0]=seg_numbers[2];
                        break;
                    case 3:
                        display[0]=seg_numbers[3];
                        break;
                    case 4:
                        display[0]=seg_numbers[4];
                        break;
                    case 5:
                        display[0]=seg_numbers[5];
                        break;
                    case 6:
                        display[0]=seg_numbers[6];
                        break;
                    case 7:
                        display[0]=seg_numbers[7];
                        break;
                    case 8:
                        display[0]=seg_numbers[8];
                        break;
                    case 9:
                        display[0]=seg_numbers[9];
                        break;
                    default:
                        display[0]=0x0FF;//OFF
                        break;
                }            
                temp /= 10;
                switch(temp%10)//middle segment
                {
                    case 0:
                        display[0]=seg_numbers[0];
                        break;
                    case 1:
                        display[0]=seg_numbers[1];
                        break;
                    case 2:
                        display[0]=seg_numbers[2];
                        break;
                    case 3:
                        display[0]=seg_numbers[3];
                        break;
                    case 4:
                        display[0]=seg_numbers[4];
                        break;
                    case 5:
                        display[0]=seg_numbers[5];
                        break;
                    case 6:
                        display[0]=seg_numbers[6];
                        break;
                    case 7:
                        display[0]=seg_numbers[7];
                        break;
                    case 8:
                        display[0]=seg_numbers[8];
                        break;
                    case 9:
                        display[0]=seg_numbers[9];
                        break;
                    default:
                        display[0]=0x0FF;//OFF
                        break;
                }
                temp /= 10;
                switch(temp%10)//leftmost segment
                {
                    case 0:
                        display[0]=0x0FF;//OFF
                        break;
                    case 1:
                        display[0]=seg_numbers[1];
                        break;
                    case 2:
                        display[0]=seg_numbers[2];
                        break;
                    case 3:
                        display[0]=seg_numbers[3];
                        break;
                    case 4:
                        display[0]=seg_numbers[4];
                        break;
                    case 5:
                        display[0]=seg_numbers[5];
                        break;
                    case 6:
                        display[0]=seg_numbers[6];
                        break;
                    case 7:
                        display[0]=seg_numbers[7];
                        break;
                    case 8:
                        display[0]=seg_numbers[8];
                        break;
                    case 9:
                        display[0]=seg_numbers[9];
                        break;
                    default:
                        display[0]=0x0FF;//OFF
                        break;
                }
            }
        }
#endif
    }

}*/

//
//void TimerInit(){
//
//    //disable interrupts
//    cli();
//
//    //Timer1 init
//
//    //external source, no prescaler available
//    TCCR1B = (ICP_ICNC<<ICNC1)|(ICP_EDGE<<ICES1)|(0<<WGM13)|
//             (0<<WGM12)|(1<<CS12)|(1<<CS11)|(T1_EDGE<<CS10)|(0<<5);
//
//
//    //Timer0 init
//    //internal source, normal operation
//    TCCR0A = (0<<COM0A1)|(0<<COM0A0)|(0<<COM0B1)|(0<<COM0B0)|
//             (0<<WGM01)|(0<<WGM00)|(0<<3)|(0<<2);
//
//    /*
//    CS02CS01CS00     Description
//    0     0     0         No clock source (Timer/Counter stopped)
//    0     0     1         clkI/O/(No prescaling)
//    0     1     0         clkI/O/8 (From prescaler)
//    0     1     1         clkI/O/64 (From prescaler)
//    1     0     0         clkI/O/256 (From prescaler)
//    1     0     1         clkI/O/1024 (From prescaler)
//    */
//    //system clock is 1MHz, prescaler set to 8, IT@488Hz
//    TCCR0B = (0<<FOC0A)|(0<<FOC0B)|(0<<WGM02)|(0<<CS02)|
//             (1<<CS01)|(0<<CS00)|(0<<5)|(0<<4);
//
//    //enable Timer1 overflow,input capture, Timer0 oveflow ITs
//    //global interrupt disabled
//#ifndef DEBUG
//    TIMSK = (1<<TOIE1)|(0<<OCIE1A)|(0<<OCIE1B)|(1<<ICIE1)|
//            (0<<OCIE0B)|(1<<TOIE0)|(0<<OCIE0A)|(0<<4);    
//#else
//    TIMSK = (0<<TOIE1)|(0<<OCIE1A)|(0<<OCIE1B)|(0<<ICIE1)|
//            (0<<OCIE0B)|(1<<TOIE0)|(0<<OCIE0A)|(0<<4);    
//#endif
//}
//
//SIGNAL(TIMER1_CAPT_vect){
////Measure
//    if(measure_enable){
//        if(measure_finished){//start new measurement
//            measure_finished = 0;
//            ICP_prev = ICR1;    
//        }else{//just completing a measurement
//            measure_finished = 1;
//            measure_enable = 0;        
//            ICP_current = ICR1;            
//        }
//    }
//}
//
//SIGNAL(TIMER1_OVF_vect){
////Display latest measure
//    uint16_t temp;
//
//    if(measure_finished){
//        temp = ICP_current - ICP_prev;
//        temp = OSC_FREQUENCY / temp; // [1/s]
//        temp = temp * 60;
//        RPM = temp;
//        measure_enable = 1;
//    }else{
//        RPM = 0;
//        measure_enable = 1;
//        measure_finished = 1;
//    }
//    measure_calculated = 1;
//}
//
//SIGNAL(TIMER0_OVF_vect){
////Change segment
//    SegSel++;
//    SegSel = SegSel%3;    
//    PORTB |= 0x1F;//deactivate display
//    PORTD |= 0x1F;
//    segmentChanged = 1;
//}
//
//

/*
SIGNAL(TIMER0_OVF_vect){
//Microtick
//Change column
    CS++;
    CS = CS%7;        //circularity
    PORTB = 0x00;    //shut diplay down
    PORTD = 0x00;
    columnChanged = 1;
    //sign that a port operation is required
}

void main(){

uint16_t temp;
    
    cli();//disable all interrupts

    PortInit();//init ports
    TimerInit();//init timers

    sei();//enable interrupts

    while(1){

        if(columnChanged){
        //new column is to be selected
            PORTD = display_columns[CS];
            //select rows
            PORTB = (0<<7)|(1<<CS);
            //select column
            columnChanged = 0;
            //clear flag
        }
#ifndef DEBUG
        if(measure_calculated){
        //displayed value needs to be refreshed
        //dispatching the number to rows and columns
        
            measure_calculated = 0;
            //clear flag
            
            temp = (Velocity%10);
            //last digit of velocity
            switch(temp)
            {
            case 0:
                display_columns[0] = display_0[0];
                display_columns[1] = display_0[1];
                display_columns[2] = display_0[2];
                break;
            case 1:
                display_columns[0] = display_1[0];
                display_columns[1] = display_1[1];
                display_columns[2] = display_1[2];
                break;
            case 2:
                display_columns[0] = display_2[0];
                display_columns[1] = display_2[1];
                display_columns[2] = display_2[2];
                break;
            case 3:
                display_columns[0] = display_3[0];
                display_columns[1] = display_3[1];
                display_columns[2] = display_3[2];
                break;
            case 4:
                display_columns[0] = display_4[0];
                display_columns[1] = display_4[1];
                display_columns[2] = display_4[2];
                break;
            case 5:
                display_columns[0] = display_5[0];
                display_columns[1] = display_5[1];
                display_columns[2] = display_5[2];
                break;
            case 6:
                display_columns[0] = display_6[0];
                display_columns[1] = display_6[1];
                display_columns[2] = display_6[2];
                break;
            case 7:
                display_columns[0] = display_7[0];
                display_columns[1] = display_7[1];
                display_columns[2] = display_7[2];
                break;
            case 8:
                display_columns[0] = display_8[0];
                display_columns[1] = display_8[1];
                display_columns[2] = display_8[2];
                break;
            case 9:
                display_columns[0] = display_9[0];
                display_columns[1] = display_9[1];
                display_columns[2] = display_9[2];
                break;
            default:
                display_columns[0] = display_no[0];
                display_columns[1] = display_no[1];
                display_columns[2] = display_no[2];
                break;
            }

            temp = (Velocity%100) / 10;
            //second digit of velocity
            
            switch(temp)
            {
            case 0:
                display_columns[4] = display_0[0];
                display_columns[5] = display_0[1];
                display_columns[6] = display_0[2];
                break;
            case 1:
                display_columns[4] = display_1[0];
                display_columns[5] = display_1[1];
                display_columns[6] = display_1[2];
                break;
            case 2:
                display_columns[4] = display_2[0];
                display_columns[5] = display_2[1];
                display_columns[6] = display_2[2];
                break;
            case 3:
                display_columns[4] = display_3[0];
                display_columns[5] = display_3[1];
                display_columns[6] = display_3[2];
                break;
            case 4:
                display_columns[4] = display_4[0];
                display_columns[5] = display_4[1];
                display_columns[6] = display_4[2];
                break;
            case 5:
                display_columns[4] = display_5[0];
                display_columns[5] = display_5[1];
                display_columns[6] = display_5[2];
                break;
            case 6:
                display_columns[4] = display_6[0];
                display_columns[5] = display_6[1];
                display_columns[6] = display_6[2];
                break;
            case 7:
                display_columns[4] = display_7[0];
                display_columns[5] = display_7[1];
                display_columns[6] = display_7[2];
                break;
            case 8:
                display_columns[4] = display_8[0];
                display_columns[5] = display_8[1];
                display_columns[6] = display_8[2];
                break;
            case 9:
                display_columns[4] = display_9[0];
                display_columns[5] = display_9[1];
                display_columns[6] = display_9[2];
                break;
            default:
                display_columns[4] = display_no[0];
                display_columns[5] = display_no[1];
                display_columns[6] = display_no[2];
                break;
            }
        }
#endif//DEBUG
    }
}
*/